package com.ztgf.sys.api.cms;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.StrUtils;
import com.ztgf.sys.models.bo.SysAreaBO;
import com.ztgf.sys.models.bo.SysAreaSaveBO;
import com.ztgf.sys.models.dto.SysAreaDTO;
import com.ztgf.sys.models.service.ISysAreaService;
import com.ztgf.sys.models.vo.SysAreaVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 区域  前端控制器
 * </p>
 *
 * @author YUE
 * @since 2020-05-25
 */
@RestController
@RequestMapping("/cms/sysArea")
@Slf4j
@Api(value = "SysAreaController",tags = "区域表接口")
public class SysAreaController {

    @DubboReference
    private ISysAreaService iSysAreaService;

    /**
     * 根据Id查询出下级所有信息
     * @param id
     * @return
     */
    @ApiOperation(value = "查询下级所有信息",notes = "根据Id查询出下级所有信息")
    @PostMapping(value = "/getInfoByCityId")
    public Result<List<SysAreaDTO>> getInfoByCityId(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        List<SysAreaDTO> areaInfoList = iSysAreaService.getInfoByCityId(id);
        return new Result<>(areaInfoList);
    }


    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<SysAreaDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        SysAreaDTO epgMainNavigationDTO = iSysAreaService.selectById(id);
        return new Result<>(epgMainNavigationDTO);
    }

    @ApiOperation(value = "区域树列表",notes = "区域树列表")
    @PostMapping("/queryAreaTreeList")
    public Result<List<SysAreaVO>> queryAreaTreeList(){
        List<SysAreaVO> areaTree = iSysAreaService.getAreaTree();
        new Result<>(areaTree);
        return new Result<>(areaTree);
    }

}

